﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zen4SyncPOCO.POCO.MEF;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition;
using Zen4SyncMefContract;
using System.Xml.Linq;


namespace Zen4SyncClient.ActivityExecutors
{
    /// <summary>
    /// Provides methods to execute activities of the "Mef" type.
    /// </summary>
    internal class Mef
    {
        [Import]
        IZen4SyncMefContract mefComponent;

        internal void ExecuteMefExecution(MefExecution activiy, MefExecutionContext context)
        {
            var catalog = new DirectoryCatalog(activiy.mefExecution_mefComponentDirectory);

            var container = new CompositionContainer(catalog);
            container.ComposeParts(this);

            mefComponent.Execute(XElement.Parse(activiy.mefExecution_metadata), XElement.Parse(context.mefExecutionContext_metadata));
        }
    }
}
